package designpatterns.strategy;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

/**
 * @author miweidong
 * @date 2021-07-28 15:28
 */
public class UserFactory {

    private UserFactory() {
    }

    private static final UserFactory USER_FACTORY = new UserFactory();

    private static final Map<Integer, IConsume> CONSUME_MAP = new HashMap<>();

    static {
        CONSUME_MAP.put(1, new OneClassUser());
        CONSUME_MAP.put(2, new TwoClassUser());
        CONSUME_MAP.put(3, new ThreeClassUser());
    }

    public IConsume creator(Integer type) {
        return Optional.ofNullable(CONSUME_MAP.get(type)).orElseThrow(() -> new NullPointerException("用户类型不存在"));
    }

    public static UserFactory getInstance() {
        return USER_FACTORY;
    }


}
